]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
workspace: Use bounding-box property from layout manager
authorJonas Dreßler <verdre@v0yd.nl>
Sun, 31 May 2020 20:47:27 +0000 (22:47 +0200)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Thu, 4 Jun 2020 17:40:09 +0000 (17:40 +0000)
Make use of the new bounding-box property we introduced for the
WindowClones layout manager in the last commit.

With this we can remove all the bounding box calculation code from the
WindowClone class and simply use the "notify::bounding-box" signal to
notify changes to our size. To make sure users of the WindowClone don't
break, we now have to convert the layout managers ClutterActorBox in our
getter function to a JS object.

Since we now also don't have to connect to the "destroy" signal of the
attached dialogs anymore, we can remove _disconnectSignals() and only
listen to "destroy" of the toplevel window.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1297

js/ui/workspace.js

index 509172f7e61ac369364346b5bde3c9a8aa711416..03b4edb3dcd2c9820161889a67856c81e3f24d3a 100644 (file)
@@ -212,17 +212,15 @@ var WindowClone = GObject.registerClass({
         this._dragSlot = [0, 0, 0, 0];
         this._stackAbove = null;
 
-        this._windowClone._sizeChangedId = this.metaWindow.connect('size-changed',
-            this._onMetaWindowSizeChanged.bind(this));
-        this._windowClone._posChangedId = this.metaWindow.connect('position-changed',
-            this._computeBoundingBox.bind(this));
-        this._windowClone._destroyId =
+        this.layout_manager.connect('notify::bounding-box', () =>
+            this.emit('size-changed'));
+
+        this._windowDestroyId =
             this.realWindow.connect('destroy', () => this.destroy());
 
         this._updateAttachedDialogs();
-        this._computeBoundingBox();
-        this.x = this._boundingBox.x;
-        this.y = this._boundingBox.y;
+        this.x = this.boundingBox.x;
+        this.y = this.boundingBox.y;
 
         this._computeWindowCenter();
 
@@ -281,10 +279,8 @@ var WindowClone = GObject.registerClass({
             parent = parent.get_transient_for();
 
         // Display dialog if it is attached to our metaWindow
-        if (win.is_attached_dialog() && parent == this.metaWindow) {
+        if (win.is_attached_dialog() && parent == this.metaWindow)
             this._doAddAttachedDialog(win, win.get_compositor_private());
-            this._onMetaWindowSizeChanged();
-        }
 
         // The dialog popped up after the user tried to close the window,
         // assume it's a close confirmation and leave the overview
@@ -298,12 +294,6 @@ var WindowClone = GObject.registerClass({
 
     _doAddAttachedDialog(metaWin, realWin) {
         let clone = new Clutter.Clone({ source: realWin });
-        clone._sizeChangedId = metaWin.connect('size-changed',
-            this._onMetaWindowSizeChanged.bind(this));
-        clone._posChangedId = metaWin.connect('position-changed',
-            this._onMetaWindowSizeChanged.bind(this));
-        clone._destroyId = realWin.connect('destroy',
-            this._onMetaWindowSizeChanged.bind(this));
 
         Shell.util_set_hidden_from_pick(clone, true);
 
@@ -327,25 +317,14 @@ var WindowClone = GObject.registerClass({
     }
 
     get boundingBox() {
-        return this._boundingBox;
-    }
-
-    _computeBoundingBox() {
-        let rect = this.metaWindow.get_frame_rect();
-
-        this.get_children().forEach(child => {
-            let realWindow;
-            if (child == this._windowClone)
-                realWindow = this.realWindow;
-            else
-                realWindow = child.source;
-
-            let metaWindow = realWindow.meta_window;
-            rect = rect.union(metaWindow.get_frame_rect());
-        });
+        const box = this.layout_manager.bounding_box;
 
-        // Convert from a MetaRectangle to a native JS object
-        this._boundingBox = { x: rect.x, y: rect.y, width: rect.width, height: rect.height };
+        return {
+            x: box.x1,
+            y: box.y1,
+            width: box.get_width(),
+            height: box.get_height(),
+        };
     }
 
     get windowCenter() {
@@ -389,27 +368,8 @@ var WindowClone = GObject.registerClass({
             parent.set_child_above_sibling(this, actualAbove);
     }
 
-    _disconnectSignals() {
-        this.get_children().forEach(child => {
-            let realWindow;
-            if (child == this._windowClone)
-                realWindow = this.realWindow;
-            else
-                realWindow = child.source;
-
-            realWindow.meta_window.disconnect(child._sizeChangedId);
-            realWindow.meta_window.disconnect(child._posChangedId);
-            realWindow.disconnect(child._destroyId);
-        });
-    }
-
-    _onMetaWindowSizeChanged() {
-        this._computeBoundingBox();
-        this.emit('size-changed');
-    }
-
     _onDestroy() {
-        this._disconnectSignals();
+        this.realWindow.disconnect(this._windowDestroyId);
 
         this.metaWindow._delegate = null;
         this._delegate = null;